home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tclUnix.h < prev    next >
C/C++ Source or Header  |  1993-05-05  |  8KB  |  336 lines

  1. /*
  2.  * tclUnix.h --
  3.  *
  4.  *    This file reads in UNIX-related header files and sets up
  5.  *    UNIX-related macros for Tcl's UNIX core.  It should be the
  6.  *    only file that contains #ifdefs to handle different flavors
  7.  *    of UNIX.  This file sets up the union of all UNIX-related
  8.  *    things needed by any of the Tcl core files.  This file
  9.  *    depends on configuration #defines in tclConfig.h
  10.  *
  11.  *    The material in this file was originally contributed by
  12.  *    Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  13.  *
  14.  * Copyright 1991 Regents of the University of California
  15.  * Permission to use, copy, modify, and distribute this
  16.  * software and its documentation for any purpose and without
  17.  * fee is hereby granted, provided that this copyright
  18.  * notice appears in all copies.  The University of California
  19.  * makes no representations about the suitability of this
  20.  * software for any purpose.  It is provided "as is" without
  21.  * express or implied warranty.
  22.  *
  23.  */
  24.  
  25. #ifndef _TCLUNIX
  26. #define _TCLUNIX
  27.  
  28. /*
  29.  * The following #defines are used to distinguish between different
  30.  * UNIX systems.  These #defines are normally set by the "config" script
  31.  * based on information it gets by looking in the include and library
  32.  * areas.  The defaults below are for BSD-based systems like SunOS
  33.  * or Ultrix.
  34.  *
  35.  * TCL_GETTOD -            1 means there exists a library procedure
  36.  *                "gettimeofday" (e.g. BSD systems).  0 means
  37.  *                have to use "times" instead.
  38.  * TCL_GETWD -            1 means there exists a library procedure
  39.  *                "getwd" (e.g. BSD systems).  0 means
  40.  *                have to use "getcwd" instead.
  41.  * TCL_SYS_ERRLIST -        1 means that the array sys_errlist is
  42.  *                defined as part of the C library.
  43.  * TCL_SYS_TIME_H -        1 means there exists an include file
  44.  *                <sys/time.h> (e.g. BSD derivatives).
  45.  * TCL_SYS_WAIT_H -        1 means there exists an include file
  46.  *                <sys/wait.h> that defines constants related
  47.  *                to the results of "wait".
  48.  * TCL_UNION_WAIT -        1 means that the "wait" system call returns
  49.  *                a structure of type "union wait" (e.g. BSD
  50.  *                systems).  0 means "wait" returns an int
  51.  *                (e.g. System V and POSIX).
  52.  * TCL_PID_T -            1 means that <sys/types> defines the type
  53.  *                pid_t.  0 means that it doesn't.
  54.  * TCL_UID_T -            1 means that <sys/types> defines the type
  55.  *                uid_t.  0 means that it doesn't.
  56.  */
  57.  
  58. #ifndef TCL_GETTOD
  59. #define TCL_GETTOD 1
  60. #endif /* TCL_GETTOD */
  61.  
  62. #ifndef TCL_GETWD
  63. #define TCL_GETWD 1
  64. #endif /* TCL_GETWD */
  65.  
  66. #ifndef TCL_SYS_ERRLIST
  67. #define TCL_SYS_ERRLIST 1
  68. #endif /* TCL_SYS_ERRLIST */
  69.  
  70. #ifndef TCL_SYS_TIME_H
  71. #define TCL_SYS_TIME_H 1
  72. #endif /* TCL_SYS_TIME_H */
  73.  
  74. #ifndef TCL_SYS_WAIT_H
  75. #define TCL_SYS_WAIT_H 1
  76. #endif /* TCL_SYS_WAIT_H */
  77.  
  78. #ifndef TCL_UNION_WAIT
  79. #define TCL_UNION_WAIT 1
  80. #endif /* TCL_UNION_WAIT */
  81.  
  82. #ifndef TCL_UID_T
  83. #define TCL_UID_T 1
  84. #endif /* TCL_UID_T */
  85.  
  86. #include <errno.h>
  87. #include <fcntl.h>
  88. #include <limits.h>
  89. #include <pwd.h>
  90. #include <signal.h>
  91. #include <sys/param.h>
  92. #include <sys/types.h>
  93. #ifdef HAVE_DIRENT
  94. #  include <dirent.h>
  95. #else
  96. #  include "compat/dirent.h"
  97. #endif
  98. #include <sys/file.h>
  99. #include <sys/stat.h>
  100. #if TCL_SYS_TIME_H
  101. #   include <sys/time.h>
  102. #else
  103. #   include <time.h>
  104. #endif
  105. #if TCL_SYS_WAIT_H
  106. #   include <sys/wait.h>
  107. #endif
  108.  
  109. /*
  110.  * Not all systems declare the errno variable in errno.h. so this
  111.  * file does it explicitly.  The list of system error messages also
  112.  * isn't generally declared in a header file anywhere.
  113.  */
  114.  
  115. extern int errno;
  116. extern int sys_nerr;
  117. extern char *sys_errlist[];
  118.  
  119. /*
  120.  * The type of the status returned by wait varies from UNIX system
  121.  * to UNIX system.  The macro below defines it:
  122.  */
  123.  
  124. #if TCL_UNION_WAIT
  125. #   define WAIT_STATUS_TYPE union wait
  126. #else
  127. #   define WAIT_STATUS_TYPE int
  128. #endif
  129.  
  130. /*
  131.  * Supply definitions for macros to query wait status, if not already
  132.  * defined in header files above.
  133.  */
  134.  
  135. #ifndef WIFEXITED
  136. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  137. #endif
  138.  
  139. #ifndef WEXITSTATUS
  140. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  141. #endif
  142.  
  143. #ifndef WIFSIGNALED
  144. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  145. #endif
  146.  
  147. #ifndef WTERMSIG
  148. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  149. #endif
  150.  
  151. #ifndef WIFSTOPPED
  152. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  153. #endif
  154.  
  155. #ifndef WSTOPSIG
  156. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  157. #endif
  158.  
  159. /*
  160.  * Supply macros for seek offsets, if they're not already provided by
  161.  * an include file.
  162.  */
  163.  
  164. #ifndef SEEK_SET
  165. #   define SEEK_SET 0
  166. #endif
  167.  
  168. #ifndef SEEK_CUR
  169. #   define SEEK_CUR 1
  170. #endif
  171.  
  172. #ifndef SEEK_END
  173. #   define SEEK_END 2
  174. #endif
  175.  
  176. /*
  177.  * The stuff below is needed by the "time" command.  If this
  178.  * system has no gettimeofday call, then must use times and the
  179.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  180.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  181.  * some might not even have HZ.
  182.  */
  183.  
  184. #if ! TCL_GETTOD
  185. #   include <sys/times.h>
  186. #   include <sys/param.h>
  187. #   ifndef CLK_TCK
  188. #       ifdef HZ
  189. #           define CLK_TCK HZ
  190. #       else
  191. #           define CLK_TCK 60
  192. #       endif
  193. #   endif
  194. #endif
  195.  
  196. /*
  197.  * Define access mode constants if they aren't already defined.
  198.  */
  199.  
  200. #ifndef F_OK
  201. #    define F_OK 00
  202. #endif
  203. #ifndef X_OK
  204. #    define X_OK 01
  205. #endif
  206. #ifndef W_OK
  207. #    define W_OK 02
  208. #endif
  209. #ifndef R_OK
  210. #    define R_OK 04
  211. #endif
  212.  
  213. /*
  214.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  215.  * define "lstat" to use "stat" instead.
  216.  */
  217.  
  218. #ifndef S_IFLNK
  219. #   define lstat stat
  220. #endif
  221.  
  222. /*
  223.  * Define macros to query file type bits, if they're not already
  224.  * defined.
  225.  */
  226.  
  227. #ifndef S_ISREG
  228. #   ifdef S_IFREG
  229. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  230. #   else
  231. #       define S_ISREG(m) 0
  232. #   endif
  233. # endif
  234. #ifndef S_ISDIR
  235. #   ifdef S_IFDIR
  236. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  237. #   else
  238. #       define S_ISDIR(m) 0
  239. #   endif
  240. # endif
  241. #ifndef S_ISCHR
  242. #   ifdef S_IFCHR
  243. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  244. #   else
  245. #       define S_ISCHR(m) 0
  246. #   endif
  247. # endif
  248. #ifndef S_ISBLK
  249. #   ifdef S_IFBLK
  250. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  251. #   else
  252. #       define S_ISBLK(m) 0
  253. #   endif
  254. # endif
  255. #ifndef S_ISFIFO
  256. #   ifdef S_IFIFO
  257. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  258. #   else
  259. #       define S_ISFIFO(m) 0
  260. #   endif
  261. # endif
  262. #ifndef S_ISLNK
  263. #   ifdef S_IFLNK
  264. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  265. #   else
  266. #       define S_ISLNK(m) 0
  267. #   endif
  268. # endif
  269. #ifndef S_ISSOCK
  270. #   ifdef S_IFSOCK
  271. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  272. #   else
  273. #       define S_ISSOCK(m) 0
  274. #   endif
  275. # endif
  276.  
  277. /*
  278.  * Make sure that MAXPATHLEN is defined.
  279.  */
  280.  
  281. #ifndef MAXPATHLEN
  282. #   ifdef PATH_MAX
  283. #       define MAXPATHLEN PATH_MAX
  284. #   else
  285. #       define MAXPATHLEN 2048
  286. #   endif
  287. #endif
  288.  
  289. /*
  290.  * Define pid_t and uid_t if they're not already defined.
  291.  */
  292.  
  293. #if ! TCL_PID_T
  294. #   define pid_t int
  295. #endif
  296. #if ! TCL_UID_T
  297. #   define uid_t int
  298. #endif
  299.  
  300. /*
  301.  * Variables provided by the C library:
  302.  */
  303.  
  304. #if defined(_sgi) || defined(__sgi)
  305. #define environ _environ
  306. #endif
  307. extern char **environ;
  308.  
  309. /*
  310.  * Library procedures used by Tcl but not declared in a header file:
  311.  */
  312.  
  313. #ifndef _CRAY
  314. extern int    access       _ANSI_ARGS_((CONST char *path, int mode));
  315. extern int    chdir       _ANSI_ARGS_((CONST char *path));
  316. extern int    close       _ANSI_ARGS_((int fd));
  317. extern int    dup2       _ANSI_ARGS_((int src, int dst));
  318. extern void    endpwent   _ANSI_ARGS_((void));
  319. extern int    execvp       _ANSI_ARGS_((CONST char *name, char **argv));
  320. extern void    _exit        _ANSI_ARGS_((int status));
  321. extern pid_t    fork       _ANSI_ARGS_((void));
  322. extern uid_t    geteuid       _ANSI_ARGS_((void));
  323. extern pid_t    getpid       _ANSI_ARGS_((void));
  324. extern char *    getwd         _ANSI_ARGS_((char *buffer));
  325. extern int    kill       _ANSI_ARGS_((pid_t pid, int sig));
  326. extern long    lseek       _ANSI_ARGS_((int fd, int offset, int whence));
  327. extern char *    mktemp       _ANSI_ARGS_((char *template));
  328. extern int    pipe       _ANSI_ARGS_((int *fdPtr));
  329. extern int    read       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  330. extern int    readlink   _ANSI_ARGS_((CONST char *path, char *buf, int size));
  331. extern int    unlink        _ANSI_ARGS_((CONST char *path));
  332. extern int    write       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  333. #endif /* _CRAY */
  334.  
  335. #endif /* _TCLUNIX */
  336.